const Mock = require('mockjs')

const List = []
const count = 100

for (let i = 0; i < count; i++) {
  List.push(Mock.mock({
    uId: '@increment',
    mid: '@increment',
    content: '@cword(10, 1024)',
    createTime: '@datetime()',
    token: 'mock token data'
  }))
}

module.exports = [
  {
    url: '/vue-element-admin/comment/list',
    type: 'get',
    response: config => {
      const { mid, page = 1, size = 20 } = config.query

      const mockList = List.sort(function(a, b) {
        return a.createTime >= b.createTime
      })

      const pageList = mockList.filter((item, index) => index < size * page && index >= size * (page - 1))

      return {
        code: 20000,
        data: {
          // total: mockList.length,
          total: 40,
          items: pageList,
          isFirstPage: Number(page) === 1,
          isLastPage: Number(page) >= (count / size)
          // nextPage: Number(page + 1)
        }
      }
    }
  },

  {
    url: '/vue-element-admin/comment/create',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  }
]
